<template>
	<view>

		<view class="mode">
			<view class="bookstatus">

				<view style="font-size: 40rpx;color:#037705;font-weight: bold;">
					{{status==1?'待付款':''}}
					{{status==2&&!state?'待配送':''}}
					{{status==3&&!state?'待收货':''}}
					{{status==4 && !state?'已完成':''}}
					{{state?'售后':''}}
				</view>

				<view>
					<view style="text-align: right;margin-bottom: 40rpx;font-size: 56rpx;color: #FF7E01">￥{{allPrice}}

					</view>

					<view class="u-flex">
						<view class="u-flex u-flex-end" v-if="status==1">
							<view class="btn gray" @click="closeOrder">取消订单</view>
							<view class="btn blue" @click="immPay">立即支付</view>
						</view>

						<view class="u-flex u-flex-end" v-if="status==3 &&!state">

							<view class="btn blue" @click="relsove">确认收货</view>
						</view>

						<view class="u-flex u-flex-end" v-if="status>1 && orderType ==1 && !state">

							<view class="btn blue" @click="serve">申请售后</view>
						</view>


						<view class="u-flex u-flex-end" v-if="state">

							<view class="btn blue " @click="kefu">

								联系客服</view>
						</view>
					</view>

				</view>
			</view>
		</view>



		<view class="top u-flex u-row-between">
			<view class="u-flex">
				<u-image src="/static/loc_icon.png" width="60" height="60"></u-image>
				<view class="u-margin-left-20" style="width: 500rpx;">
					<view>
						<text style="font-size: 32rx;font-weight: bold;">{{address.name}}</text>
						<text style="color:#999999;margin-left: 20rpx;">{{address.phone}}</text>
					</view>
					<view class="">
						{{address.address}}
					</view>
				</view>
			</view>

		</view>

		<view v-for="(item,index) in list" :key="index" class="list">
			<view class="u-flex">
				<u-image :src="item.cover" width="160" height="160"></u-image>
				<view class="right">
					<view class="title">
						{{item.name}}
					</view>

					<view class="controls">
						<view class="price">
							￥{{item.price}}
						</view>
						<view class="num">
							x{{item.num}}
						</view>
					</view>
				</view>


			</view>
		</view>

		<view class="mode">
			<u-cell-group>
				<u-cell-item title="商品运费" :value="yunfei+'元'" :arrow="false"></u-cell-item>
				<u-cell-item title="商品备注" :value="liuyan" :arrow="false">

				</u-cell-item>
			</u-cell-group>
		</view>




		<view class="mode">
			<u-cell-group>
				<u-cell-item title="物流信息" :value="expressNo" :arrow="false" v-if="expressNo"></u-cell-item>
				<u-cell-item title="订单号" :value="booknumbe" :arrow="false" v-if="booknumbe"></u-cell-item>

			</u-cell-group>
		</view>


		<view class="mode">
			<u-cell-group>
				<u-cell-item title="提交时间" :value="submittime" :arrow="false"></u-cell-item>
				<u-cell-item title="付款时间" :value="payTime" :arrow="false" v-if="payTime"></u-cell-item>
				<u-cell-item title="配送时间" :value="deliverTime" :arrow="false" v-if="deliverTime"></u-cell-item>
				<u-cell-item title="收货时间" :value="signTime" :arrow="false" v-if="signTime"></u-cell-item>





			</u-cell-group>
		</view>



		<u-toast ref="uToast" />

		<paystatus ref="children"></paystatus>

	</view>
</template>

<script>
	import payway from '../../common/wxpay.js';
	export default {

		data() {
			return {
				liuyan: "",
				status: "",
				state: "",
				yunfei: "",
				allPrice: "",
				payway: "",
				realprice: "",
				conpund: "",
				submittime: "",
				deliverTime: "",
				payTime: "",
				signTime: '',
				booknumbe: "",
				expressNo: "",
				address: {
					name: "",
					phone: "",
					address: ""
				},
				list: [],
				id: "",
				orderType: "",
				ptState: ""
			}
		},
		onLoad(options) {
			if (options.id) {
				this.id = options.id
			}
			this.getDetail()


		},
		methods: {
			relsove() {
				uni.showModal({
					content: "是否确认收货?",
					success: (res) => {
						if (res.confirm) {
							this.$u.post('/api/indent/signFor', {
								order_id: this.id
							}, {}).then(res => {

								this.$refs.uToast.show({
									title: '收货成功',
									type: 'success',
									back: true,
								})


							}).catch(err => {})
						}
					}
				})
			},
			immPay() {
				this.$u.post('/api/indent/pay', {
					order_id: this.id
				}, {}).then(res => {
					var packages = res.data.package;
					var {
						noncestr,
						timestamp,
						signtype,
						paysign
					} = res.data
					payway.wx(timestamp, noncestr, packages, signtype, paysign).then(res => {
						this.$refs.uToast.show({
							title: '支付成功',
							type: 'success',
							back: true,
						})
					}).catch(err => {
						console.log(res)
					})

				}).catch(err => {})

			},



			closeOrder() {
				this.$u.post('/api/indent/clearOrder', {
					order_id: this.id
				}, {}).then(res => {

					this.$refs.uToast.show({
						title: '取消成功',
						type: 'default',
						back: true,

					})
				}).catch(err => {})

			},
			getDetail() {
				this.$u.post('/api/indent/orderDetail', {
					order_id: this.id
				}, {}).then(res => {
					this.status = res.data.status;
					this.allPrice = res.data.payMoney
					this.address.address = res.data.address;
					this.address.phone = res.data.phone
					this.address.name = res.data.recipient;
					this.list = res.data.goods;
					this.yunfei = res.data.expressFee;
					this.liuyan = res.data.remark
					this.conpund = res.data.saleMoney
					this.payway = res.data.payWay
					this.realprice = res.data.totalMoney
					this.booknumbe = res.data.outTradeNo
					this.submittime = res.data.createTime
					this.state = res.data.state,
						this.orderType = res.data.orderType
					this.ptState = res.data.ptState
					this.payTime = res.data.payTime
					this.deliverTime = res.data.deliverTime
					this.signTime = res.data.signTime

					this.expressNo = res.data.expressNo


				}).catch(err => {})
			},
			serve() {
				uni.navigateTo({
					url: "./serve?id=" + this.id
				})
			},
			kefu() {
				this.$u.post('/api/index/getConfig', {

				}, {}).then(res => {
					uni.makePhoneCall({
						phoneNumber: res.data.kfTel
					})

				}).catch(err => {})
			}
		}
	}
</script>

<style lang="scss">
	page {
		padding-bottom: 200rpx;
	}

	.share {

		position: relative;

		button {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			z-index: 999;
			opacity: 0;
		}
	}

	.bookstatus {
		display: flex;
		justify-content: space-between;
		padding: 30rpx;

		.btn {
			padding: 14rpx 30rpx;
			font-size: 24rpx;
			border-radius: 50rpx;
			margin-left: 20rpx;

		}

		.gray {
			color: #999999;
			background: #F6F6F6;
			display: table;
		}

		.blue {
			background: #037705;
			color: #FFFFFF;
			display: table;
		}

	}





	.mode {

		background: #FFFFFF;
		box-shadow: 0px 4rpx 6rpx rgba(209, 209, 209, 0.26);
		border-radius: 20rpx;
		width: 690rpx;
		margin: 40rpx auto;
	}

	.top {
		width: 690rpx;
		background: #FFFFFF;
		box-shadow: 0px 4rpx 6rpx rgba(209, 209, 209, 0.26);
		border-radius: 20rpx;
		margin: 40rpx auto;
		padding: 30rpx;
		display: flex;
		justify-content: space-between;
	}

	.list {
		width: 690rpx;
		height: 240rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 6rpx rgba(209, 209, 209, 0.26);
		border-radius: 20rpx;
		margin: auto;
		padding: 20rpx;
		display: flex;
		align-items: center;

		.right {
			margin-left: 20rpx;
			width: 450rpx;

			.size {
				background: #F6F6F6;
				border-radius: 30rpx;
				padding: 7rpx 30rpx;
				text-align: center;
				display: table !important;
				font-size: 24rpx;
				color: #999999;
				margin: 20rpx 0;
			}
		}

		.controls {
			display: flex;
			justify-content: space-between;

			.price {
				color: #FF7E01;
				font-size: 36rpx;
			}

			.num {
				color: #FF7E01;
				font-size: 36rpx;

			}
		}



	}



	.sure {
		width: 200rpx;
		height: 80rpx;
		background: #628DFF;
		border-radius: 40rpx;
		text-align: center;
		font-size: 28rpx;
		line-height: 80rpx;
		color: #fff;

	}
</style>
